package cn.scnu.model.enums;

import cn.scnu.model.dto.EnumTypeDTO;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @author hqz
 * @className QueryOperationEnum
 * @createTime 2024年11月28日 17:46:00
 */
@Getter
public enum QueryOperationEnum {
    EQUALS("equals", "等于"),
    NOT_EQUALS("notEquals", "不等于"),
    GREATER_THAN("greaterThan", "大于"),
    LESS_THAN("lessThan", "小于"),
    GREATER_THAN_OR_EQUALS("greaterThanOrEquals", "大于等于"),
    LESS_THAN_OR_EQUALS("lessThanOrEquals", "小于等于"),
    CONTAINS("contains", "包含"),
    ORDER_ASC("orderAsc", "升序"),
    ORDER_DESC("orderDesc", "降序");

    @JsonValue
    @EnumValue
    private final String operation;
    private final String chineseOperation;

    QueryOperationEnum(String operation, String chineseOperation) {
        this.operation = operation;
        this.chineseOperation = chineseOperation;
    }

    public static QueryOperationEnum getQueryOperationEnum(String operation) {
        for (QueryOperationEnum queryOperationEnum : QueryOperationEnum.values()) {
            if (queryOperationEnum.getOperation().equals(operation)) {
                return queryOperationEnum;
            }
        }
        return null;
    }

    //     获取枚举类型List
    public static List<EnumTypeDTO> getQueryOperationEnumList() {
        List<EnumTypeDTO> enumTypeList = new ArrayList<>();
        for (QueryOperationEnum typeEnum : values()) {
            EnumTypeDTO enumTypeDTO = new EnumTypeDTO();
            enumTypeDTO.setValue(typeEnum.getOperation());
            enumTypeDTO.setLabel(typeEnum.getChineseOperation());
            enumTypeList.add(enumTypeDTO);
        }
        return enumTypeList;
    }

}
